/**
 * Created by Administrator on 2017/6/28.
 */
$(document).ready(function(){
    $("#contact-submit").click(function(){
        var name=$("#name").val();
        var email=$("#email").val();
        var subject=$("#subject").val();
        var message=$("#message").val();

        if(!name){
            window.alert("姓名为空，请输入姓名！");
        }else if(!email){
            window.alert("邮箱为空，请输入邮箱！");
        }else if(!email.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/))
        {
            window.alert("邮箱格式不正确！请重新输入");
            $("#email1").focus();
        }else if(!subject){
            window.alert("主题为空，请输入主题！");
        }else if(!message){
            window.alert("内容为空，请输入内容！");
        }
        if(name&&email&&subject&&message){
            var content={
                name:$("#name").val(),
                email:$("#email").val(),
                subject:$("#subject").val(),
                message:$("#message").val()
            };
            $.ajax({
                type: 'post',
                url: '/contact',
                data: content,
                dataType: "text",
                success: function(data) {
                    window.alert("提交成功,我们将尽快和您联系！");
                },
                error:function(){

                }
            });
        }
    });
});